"""
MAESS备份系统异常定义
"""


class BackupBaseError(Exception):
    """备份系统基础异常"""
    
    def __init__(self, message: str, error_code: str = "BACKUP_ERROR", status_code: int = 500):
        self.message = message
        self.error_code = error_code
        self.status_code = status_code
        super().__init__(self.message)


class BackupError(BackupBaseError):
    """备份操作异常"""
    
    def __init__(self, message: str, error_code: str = "BACKUP_OPERATION_FAILED", status_code: int = 500):
        super().__init__(message, error_code, status_code)


class RestoreError(BackupBaseError):
    """恢复操作异常"""
    
    def __init__(self, message: str, error_code: str = "RESTORE_OPERATION_FAILED", status_code: int = 500):
        super().__init__(message, error_code, status_code)


class BackupNotFoundException(BackupBaseError):
    """备份不存在异常"""
    
    def __init__(self, backup_id: str):
        message = f"备份 {backup_id} 不存在"
        super().__init__(message, "BACKUP_NOT_FOUND", 404)


class BackupValidationError(BackupBaseError):
    """备份验证异常"""
    
    def __init__(self, message: str):
        super().__init__(message, "BACKUP_VALIDATION_FAILED", 400)


class BackupFileError(BackupBaseError):
    """备份文件异常"""
    
    def __init__(self, message: str, error_code: str = "BACKUP_FILE_ERROR", status_code: int = 500):
        super().__init__(message, error_code, status_code)


class BackupCompressionError(BackupFileError):
    """备份压缩异常"""
    
    def __init__(self, message: str):
        super().__init__(message, "BACKUP_COMPRESSION_FAILED", 500)


class BackupDecompressionError(BackupFileError):
    """备份解压异常"""
    
    def __init__(self, message: str):
        super().__init__(message, "BACKUP_DECOMPRESSION_FAILED", 500)


class DatabaseBackupError(BackupError):
    """数据库备份异常"""
    
    def __init__(self, message: str):
        super().__init__(message, "DATABASE_BACKUP_FAILED", 500)


class DatabaseRestoreError(RestoreError):
    """数据库恢复异常"""
    
    def __init__(self, message: str):
        super().__init__(message, "DATABASE_RESTORE_FAILED", 500)


class RedisBackupError(BackupError):
    """Redis备份异常"""
    
    def __init__(self, message: str):
        super().__init__(message, "REDIS_BACKUP_FAILED", 500)


class RedisRestoreError(RestoreError):
    """Redis恢复异常"""
    
    def __init__(self, message: str):
        super().__init__(message, "REDIS_RESTORE_FAILED", 500)


class FilesystemBackupError(BackupError):
    """文件系统备份异常"""
    
    def __init__(self, message: str):
        super().__init__(message, "FILESYSTEM_BACKUP_FAILED", 500)


class FilesystemRestoreError(RestoreError):
    """文件系统恢复异常"""
    
    def __init__(self, message: str):
        super().__init__(message, "FILESYSTEM_RESTORE_FAILED", 500)


class SchedulerError(BackupBaseError):
    """调度器异常"""
    
    def __init__(self, message: str, error_code: str = "SCHEDULER_ERROR", status_code: int = 500):
        super().__init__(message, error_code, status_code)


class SchedulerJobError(SchedulerError):
    """调度任务异常"""
    
    def __init__(self, message: str, error_code: str = "SCHEDULER_JOB_ERROR", status_code: int = 500):
        super().__init__(message, error_code, status_code)


class BackupSizeLimitExceededError(BackupError):
    """备份大小超出限制异常"""
    
    def __init__(self, size: int, limit: int):
        message = f"备份大小 {size} 超出限制 {limit}"
        super().__init__(message, "BACKUP_SIZE_LIMIT_EXCEEDED", 400)


class BackupQuotaExceededError(BackupError):
    """备份配额超出异常"""
    
    def __init__(self, message: str):
        super().__init__(message, "BACKUP_QUOTA_EXCEEDED", 400)


class BackupInProgressError(BackupError):
    """备份正在进行中异常"""
    
    def __init__(self, backup_type: str):
        message = f"{backup_type} 备份正在进行中，请稍后再试"
        super().__init__(message, "BACKUP_IN_PROGRESS", 409)


class RestoreInProgressError(RestoreError):
    """恢复正在进行中异常"""
    
    def __init__(self):
        message = "恢复操作正在进行中，请稍后再试"
        super().__init__(message, "RESTORE_IN_PROGRESS", 409)


class InvalidBackupTypeError(BackupValidationError):
    """无效的备份类型异常"""
    
    def __init__(self, backup_type: str):
        message = f"无效的备份类型: {backup_type}"
        super().__init__(message)


class InvalidRestoreModeError(BackupValidationError):
    """无效的恢复模式异常"""
    
    def __init__(self, restore_mode: str):
        message = f"无效的恢复模式: {restore_mode}"
        super().__init__(message)


class BackupPermissionError(BackupBaseError):
    """备份权限异常"""
    
    def __init__(self, message: str):
        super().__init__(message, "BACKUP_PERMISSION_DENIED", 403)


class BackupTimeoutError(BackupError):
    """备份超时异常"""
    
    def __init__(self, message: str = "备份操作超时"):
        super().__init__(message, "BACKUP_TIMEOUT", 504)


class BackupLockError(BackupError):
    """备份锁异常"""
    
    def __init__(self, message: str = "无法获取备份锁"):
        super().__init__(message, "BACKUP_LOCK_ERROR", 500)


class BackupCorruptedException(BackupFileError):
    """备份文件损坏异常"""
    
    def __init__(self, backup_id: str):
        message = f"备份文件 {backup_id} 已损坏"
        super().__init__(message, "BACKUP_CORRUPTED", 500)
